package org.zxt.web.context.handler.parser;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.zxt.web.context.WebContext;
import org.zxt.web.context.handler.ArgumentParser;
import org.zxt.web.nio.IHTTPSession;

import javax.annotation.Resource;
import java.lang.reflect.Parameter;

public class PageParamParser implements ArgumentParser {
    @Override
    public boolean support(Parameter p) {
        return p.getType() == Page.class || p.getType() == IPage.class;
    }

    @Override
    public Object parse(Parameter p, WebContext webContext, IHTTPSession session) {
        int page = Integer.parseInt(session.getParam("current", "0"));
        int size = Integer.parseInt(session.getParam("size", "10"));
        return new Page<>(page, size);
    }
}
